package cn.kaguyaever.dao.impl;

import cn.kaguyaever.dao.CandidateDao;
import cn.kaguyaever.entity.Candidate;
import cn.kaguyaever.entity.Judge;

import java.util.List;

public class CandidateDaoImpl extends BaseDao<Candidate> implements CandidateDao {
    public int createCandidate(Candidate candidate){
        String sql = "insert into candidate(`candidateId`,`name`,`count`,`voteId`) values(?,?,?,?)";
        return update(sql,candidate.getCandidateId(),candidate.getName(),candidate.getCount(),candidate.getVoteId());
    }

    public List<Candidate> queryAllCandidateByVoteId(String voteId){
        String sql = "select `candidateId`,`name`,`count` , `voteId` from candidate where voteId = ?";
        return queryForList(sql,voteId);
    }

    public int voteCandidate(Integer candidateId){
        String sql = "update candidate set count= ifnull(count,0) + 1 where candidateId = ? ";
        return update(sql,candidateId);
    }

    public int deleteCandidate(String voteId){
        String sql = "delete from candidate where voteId = ?";
        return update(sql,voteId);
    }
}
